package com.ft.f_springboot_route.service.impl;

import com.ft.f_springboot_route.bean.Shop;
import com.ft.f_springboot_route.mapper.ShopMapper;
import com.ft.f_springboot_route.service.ShopService;
import com.ft.f_springboot_route.utils.JsonUtils;
import com.ft.f_springboot_route.utils.Pager;
import com.ft.f_springboot_route.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopServiceImpl implements ShopService {
    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private ShopMapper shopMapper;

    @Override
    public Pager<Shop> pager(Integer currentPage, String shopName, String shopTel, String shopAddress) {
        Pager<Shop> pagers=new Pager<>();
        if(currentPage == null || currentPage < 0){
            currentPage = 1;
        }
        int index=(currentPage-1)*4;
        List<Shop> shops = shopMapper.SelMultiShopList(index,shopName,shopTel,shopAddress);
        System.out.println("---------------------------");
        pagers.setList(shops);
        pagers.setCurrentPage(currentPage);
        pagers.setPageSize(4);

        Long shopTotal = shopMapper.getShopTotal(shopName, shopTel, shopAddress);
        pagers.setTotal(shopTotal);
        return pagers;
    }

    @Override
    public long getShopTotal(String shopName, String shopTel, String shopAddress) {
        return shopMapper.getShopTotal(shopName,shopTel,shopAddress);
    }

    @Override
    public List<Shop> SelectShopList() {
        List<Shop> shops = shopMapper.SelectShopList();
        return shops;
    }

    @Override
    public List<Shop> SelMultiShopList(Integer currentPage, String shopName, String shopTel, String shopAddress) {
        return shopMapper.SelMultiShopList(currentPage,shopName,shopTel,shopAddress);
    }

    @Override
    public Shop SelectShopId(Integer shop_id) {
        Shop shop = shopMapper.SelectShopId(shop_id);
        return shop;
    }

    @Override
    public void AddShop(Shop shop) {
        shopMapper.AddShop(shop);
    }

    @Override
    public void DelShopById(Integer shop_id) {
        shopMapper.DelShopById(shop_id);
    }

    @Override
    public void EditShop(Shop shop) {
        shopMapper.EditShop(shop);
    }
}
